package com.hb.znpt.app;

import android.util.Log;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;

import com.alibaba.fastjson.JSON;
import com.hb.znpt.BuildConfig;
import com.hb.znpt.bean.SimpleResponse;
import com.hb.znpt.utils.Constants;
import com.jeremyliao.liveeventbus.LiveEventBus;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import com.tencent.bugly.crashreport.CrashReport;
import com.unitlib.base.base.BaseApplication;
import com.unitlib.base.utils.constant.LiveConstants;
import com.unitlib.net.config.NetConfig;

import rxhttp.wrapper.callback.Function;
import rxhttp.wrapper.param.RxHttp;

/**
 * @Description: 描述
 * @Author: houbing
 * @CreateDate: 2021/9/2 13:08
 */
public class App extends BaseApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        // 初始化网络插件
        NetConfig.init(this, Constants.baseUrl, BuildConfig.DEBUG);
        RxHttp.setResultDecoder(new Function<String, String>() {
            @Override
            public String apply(String body) throws Exception {
                SimpleResponse response = JSON.parseObject(body, SimpleResponse.class);
                Log.e("App-mian", response.toString());
                if (response.getReturn_code().equals("000007")) {
                    LiveEventBus.get(LiveConstants.LIVEDATABUS_KEY_GLOBAL_FINISH).post(1);
                }
                return body;
            }
        });
        // Logger初始化
        Logger.addLogAdapter(new AndroidLogAdapter());
        // 初始化bugly
        CrashReport.initCrashReport(getApplicationContext(), "d226e3aada", BuildConfig.DEBUG);
    }

}
